// pages/refund/refund.js
const util = require("../../utils/util.js");
var app = getApp();
const requestManager = require("../../utils/request.js");
var router = require('../../utils/router.js');
const pageName = "PersonalCenter "
const config = require("../../utils/config.js")
let paramsLogistics = {
  userId: util.getUserInfo().userId
}
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    tlogisticsType:[],// 物流类型
    detailData: null,
    index: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getDetaildata(options.orderid,options.serviceId)
    // 获取物流类型
    this.geTlogisticsType()
    paramsLogistics.orderId = options.orderid
    paramsLogistics.serviceId = options.serviceId
    paramsLogistics.afterSaale = options.afterSaale
  },
  // 提交物流信息
  submitLogistics(){
    if(!paramsLogistics.refundShipType){
      return util.noIconToast('请选择物流公司')
    }
    if(!paramsLogistics.refundShipTradeNo){
      return util.noIconToast('请填写物流单号')
    }
    console.log(paramsLogistics)
    requestManager.getDataResult(requestManager.service_refund_ship, paramsLogistics, "POST").then(res => {
      let url = "/pages/logisticsinfo/logisticsinfo";
        router.route.setAction(router.NAVIGATE_TO)
          .setParams([`orderId=${paramsLogistics.orderId}&serviceId=${paramsLogistics.serviceId}&afterSaale=${paramsLogistics.afterSaale}`])
          .setUrl(url)
          .run()
    })
  },
  // 获取物流类型
  geTlogisticsType(){
    requestManager.getDataResult(requestManager.get_ship_info, {}, "GET").then(res => {
      this.setData({
        tlogisticsType: res.list?res.list:[]
      })
    })
  }, 
  //获取订单详情数据
  getDetaildata(orderid,serviceId) {
    // orderid=82785&afterSaale=true&serviceId=31
    let params = {
      userId: util.getUserInfo().userId,
      orderId: orderid || 82785,
      serviceId:serviceId
    }
    // requestManager.getDataResult(requestManager.service_view, params, "GET").then(res => {
    requestManager.getDataResult(requestManager.service_view, params, "GET").then(res => {
      this.setData({
        detailData: res.data
      })
    })
  },
  bindblurChange(e){
    paramsLogistics.refundShipTradeNo = e.detail.value
  },
  bindPickerChange: function (e) {
    this.setData({
      index: e.detail.value
    })
    paramsLogistics.refundShipType = this.data.tlogisticsType[e.detail.value].id
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})